package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.StrategyCatalogQueryObject;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/strategyCatalogs")
public class StrategyCatalogController {
    @Autowired
    private IStrategyCatalogService strategyCatalogService;
    @Autowired
    private IStrategyService strategyService;

    @RequestMapping("/list")
    public String list(Model model,@ModelAttribute("qo")StrategyCatalogQueryObject qo){
        qo.setOrderBy("sequence ASC");
        model.addAttribute("trategyList",strategyService.listAll());
        model.addAttribute("pageInfo",strategyCatalogService.query(qo));
        return "/strategyCatalogs/list";
    }
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(StrategyCatalog strategyCatalog){
        strategyCatalogService.saveOrUpdate(strategyCatalog);
        return new JsonResult() ;
    }
    @RequestMapping("/listByStrategyId")
    @ResponseBody
    public List<StrategyCatalog> listByStrategyId(Long strategyId){
        List<StrategyCatalog> list = strategyCatalogService.listByStrategyId(strategyId);
        return list;
    }
}
